package manager.modulo.financeiro.dao;

import java.sql.SQLException;
import manager.auxiliares.MensagemExcessao;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.LinkedList;
import manager.principal.fonte.JanelaLogin;
import manager.interfaces.InterfaceDao;

/**
 * Esta classe será utilizada para cadastra a entidade user no banco de dados
 * @author Thiago
 */
public class EntryDescriptionFinancialEntryDao implements InterfaceDao {

    private int idFinancialEntryDescription;
    private int idFinancialEntry;

    /**
     * Inicializando as variáveis
     */
    public EntryDescriptionFinancialEntryDao() {
        idFinancialEntry = 0;
        idFinancialEntryDescription = 0;
    }

    public EntryDescriptionFinancialEntryDao(int newIdFinancialEntry, int newIdFinancialEntryDescription) {
        idFinancialEntry = newIdFinancialEntry;
        idFinancialEntryDescription = newIdFinancialEntryDescription;
    }

    public static int getIdFinancialEntryByIdDescription(int idFinancialEntryDescription) {
        try {

            String sql = "SELECT id_financial_entry FROM ent_des_fin_ent WHERE id_financial_entry_description = ?";
            PreparedStatement preparedStatement = JanelaLogin.getConnection().prepareStatement(sql);
            preparedStatement.setInt(1, idFinancialEntryDescription);
            ResultSet resultSet = preparedStatement.executeQuery();
            int idFinancialEntry = 0;
            if (resultSet.first()) {
                idFinancialEntry = resultSet.getInt("id_financial_entry");
            }
            resultSet.close();
            preparedStatement.close();
            return idFinancialEntry;
        } catch (Exception e) {
            MensagemExcessao.mostrarMensagem(e, "Buscando Lançamentos");
            return 0;
        }
    }

    /**
     * Insere um usuário no banco
     */
    public void inserir() throws SQLException {
        String sql = "INSERT INTO ent_des_fin_ent (id_financial_entry_description,id_financial_entry) VALUES(?,?)";
        PreparedStatement preparedStatement = JanelaLogin.getConnection().prepareStatement(sql);

        preparedStatement.setInt(1, idFinancialEntryDescription);
        preparedStatement.setInt(2, idFinancialEntry);
        preparedStatement.executeUpdate();

        preparedStatement.close();
    }

    public void deletar() throws SQLException {
        String sql = "DELETE FROM ent_des_fin_ent WHERE id_financial_entry = ?";
        PreparedStatement preparedStatement = JanelaLogin.getConnection().prepareStatement(sql);

        preparedStatement.setInt(1, idFinancialEntry);
        preparedStatement.executeUpdate();

        preparedStatement.close();
    }

    public void atualizar() throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void buscar(int idSearch) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getIdFinancialEntry() {
        return idFinancialEntry;
    }

    public void setIdFinancialEntry(int idFinancialEntry) {
        this.idFinancialEntry = idFinancialEntry;
    }

    public int getIdFinancialEntryDescription() {
        return idFinancialEntryDescription;
    }

    public void setIdFinancialEntryDescription(int idFinancialEntryDescription) {
        this.idFinancialEntryDescription = idFinancialEntryDescription;
    }

    public LinkedList<String> buscar(String opcao, String buscado, boolean sizeLimit) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
